a = 6*343**1156-5*49**1147+4*7**1153-875
s = 0
while a > 0:
    s += a % 7
    a = a // 7
print(s)